// pages/label/label.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    clickNum: 0,
    labelList: [{
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },
      {
        name: "标签",
        status: 0
      },

    ]
  },
  changeLabel(data) {
    // console.log(data.currentTarget.dataset.index)
    let status = `labelList[` + data.currentTarget.dataset.index + `].status`
    let num = data.currentTarget.dataset.index
    if (this.data.labelList[num].status) {
      this.setData({
        [status]: 0,
        clickNum: this.data.clickNum - 1
      })
    } else {
      if (this.data.clickNum > 4) {
        wx.showToast({
          title: '最多可选择五个标签',
          icon: 'none'
        })
      } else {
        let _num = 0
        for (let i = 0; i < this.data.labelList.length; i++) {
          if (this.data.labelList[i].status) {
            _num = _num + 1
          }
        }
        this.setData({
          clickNum: _num + 1,
          [status]: 1
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})